package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.IDongtaiService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Dongtai;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 动态管理 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Controller
@RequestMapping("/system/dongtai")
public class DongtaiController extends BaseController
{
    private String prefix = "system/dongtai";
	
	@Autowired
	private IDongtaiService dongtaiService;
	
	@RequiresPermissions("system:dongtai:view")
	@GetMapping()
	public String dongtai()
	{
	    return prefix + "/dongtai";
	}
	
	/**
	 * 查询动态管理列表
	 */
	@RequiresPermissions("system:dongtai:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Dongtai dongtai)
	{
		startPage();
        List<Dongtai> list = dongtaiService.selectDongtaiList(dongtai);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出动态管理列表
	 */
	@RequiresPermissions("system:dongtai:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Dongtai dongtai)
    {
    	List<Dongtai> list = dongtaiService.selectDongtaiList(dongtai);
        ExcelUtil<Dongtai> util = new ExcelUtil<Dongtai>(Dongtai.class);
        return util.exportExcel(list, "dongtai");
    }
	
	/**
	 * 新增动态管理
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存动态管理
	 */
	@RequiresPermissions("system:dongtai:add")
	@Log(title = "动态管理", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Dongtai dongtai)
	{	if(dongtai != null){
		SysUser user = getSysUser();
		dongtai.setFabuId(user.getUserId());
	}
		return toAjax(dongtaiService.insertDongtai(dongtai));
	}

	/**
	 * 修改动态管理
	 */
	@GetMapping("/edit/{dongtaiId}")
	public String edit(@PathVariable("dongtaiId") Integer dongtaiId, ModelMap mmap)
	{
		Dongtai dongtai = dongtaiService.selectDongtaiById(dongtaiId);
		mmap.put("dongtai", dongtai);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存动态管理
	 */
	@RequiresPermissions("system:dongtai:edit")
	@Log(title = "动态管理", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Dongtai dongtai)
	{
		SysUser user = getSysUser();
		dongtai.setFabuId(user.getUserId());
		return toAjax(dongtaiService.updateDongtai(dongtai));
	}
	
	/**
	 * 删除动态管理
	 */
	@RequiresPermissions("system:dongtai:remove")
	@Log(title = "动态管理", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(dongtaiService.deleteDongtaiByIds(ids));
	}
	
}
